#include<bits/stdc++.h>
using namespace std;
mt19937_64 rnd(time(0));
typedef long long ll;
const int N = 1e6+5,mod1 = 998244353,bs1 = 19491001,mod2 = 1011451423,bs2 = 31;
int n;
int A[N],a[N],b[N<<1];
int L[N<<1],R[N<<1];
int nxt[N];
int id[N],tot,val[N];
bool cmp(int i,int j){return A[i] < A[j];}
int s[N];
ll pw1[N],hsh11[N],hsh12[N],pw2[N],hsh21[N],hsh22[N];
ll hs11(int l,int r){return (hsh11[r] - hsh11[l-1]*pw1[r-l+1]%mod1 + mod1)%mod1;}
ll hs12(int l,int r){return (hsh12[l] - hsh12[r+1]*pw1[r-l+1]%mod1 + mod1)%mod1;}
ll hs21(int l,int r){return (hsh21[r] - hsh21[l-1]*pw2[r-l+1]%mod2 + mod2)%mod2;}
ll hs22(int l,int r){return (hsh22[l] - hsh22[r+1]*pw2[r-l+1]%mod2 + mod2)%mod2;}
vector<int>vl[N],vr[N];
void solve()
{
    cin>>n;
    for(int i = 1;i <= n;i++) cin>>a[i],A[a[i]+1] = i,vl[i].clear(),vr[i].clear();
    for(int i = 2;i <= 2*n;i++) cin>>b[i];
    for(int i = 2;i <= 2*n;i++)
    {
        if(!((b[i]^i)&1))
        {
            cout<<"-1\n";
            return ;
        }
        if(b[i] >= i)
        {
            cout<<"-1\n";
            return ;
        }
        if(b[i] >= 2*n-i+2)
        {
            cout<<"-1\n";
            return ;
        }
        L[i] = (i-b[i]+1)/2;
        R[i] = (i+b[i]-1)/2;
        if(L[i] > 1) vl[L[i]-1].push_back(R[i]+1);
        if(R[i] < n) vr[R[i]+1].push_back(L[i]-1);
    }
    tot = 0;
    for(int i = 1;i <= n;i++) a[i]++;
    for(int i = 1,cl = 0;i <= n;i++)
    {
        int flag = 0;
        if(i == 1 || A[a[i]+1] < A[a[i-1]+1]) flag |= 1;
        for(auto x:vl[a[i]])
            if(A[x] > cl && A[x] < i) flag |= 2;//如果x在这个区间里
        for(auto x:vr[a[i]])
            if(A[x] > cl && A[x] < i) flag |= 4;
        if(flag)
        {
            //cout<<"!"<<i<<" "<<flag<<"\n";
            ++tot;
            cl = i-1;
        }
        s[a[i]] = tot;
    }
    if(tot > 26)
    {
        cout<<"-1\n";
        return ;
    }
    //for(int i = 1;i <= n;i++) cout<<s[i]<<" ";
    //cout<<"\n";
    pw1[0] = pw2[0] = 1;
    hsh12[n+1] = hsh22[n+1] = 0;
    for(int i = 1;i <= tot;i++)
    {
        val[i] = i;
        swap(val[i],val[rnd()%i+1]);
    }
    for(int i = 1;i <= n;i++)
    {
        pw1[i] = pw1[i-1]*bs1%mod1;
        pw2[i] = pw2[i-1]*bs2%mod2;
    }
    for(int i = 1;i <= n;i++)
    {
        hsh11[i] = (hsh11[i-1]*bs1 + val[s[i]])%mod1;
        hsh21[i] = (hsh21[i-1]*bs2 + val[s[i]])%mod2;
    }
    for(int i = n;i;i--)
    {
        hsh12[i] = (hsh12[i+1]*bs1 + val[s[i]])%mod1;
        hsh22[i] = (hsh22[i+1]*bs2 + val[s[i]])%mod2;
    }
    for(int i = 2;i <= 2*n;i++)
    {
        if(hs11(L[i],R[i]) != hs12(L[i],R[i]) || hs21(L[i],R[i]) != hs22(L[i],R[i]))
        {
            cout<<"-1\n";
            return ;
        }
        if(L[i] > 1 && R[i] < n && s[L[i]-1] == s[R[i]+1])
        {
            cout<<"-1\n";
            return ;
        }
    }
    for(int i = 1;i <= n;i++) cout<<char('a'+s[i]-1);
    cout<<"\n";
}
int main()
{
    //system("fc string.out string4.ans");
    freopen("string.in","r",stdin);
    freopen("string.out","w",stdout);
    ios::sync_with_stdio(false);cin.tie(0);
    int T;cin>>T;
    while(T--) solve();
    return 0;
}